<?php 
class BaseController_Controller extends CI_Controller {
 var $loginuser;
 var $curmenu; 
 var $appmsg;
 var $msgdebug;
 var $vwdata;
  function __construct()
  {
	
	parent::__construct();

    $this->load->helper('url');	

    // ensure already signed in
    if (!is_array($this->session->userdata('logged_in'))  ) {		
      redirect( "scp/login" );
    }
	else	{		
		$this->loginuser=$this->session->userdata('logged_in');			
		if($this->loginuser['uname']=='')
			redirect( "scp/login" );
		//if($this->loginuser['changepassword']==true)
			//redirect("scp/secure")
	}
  }

  function showdebug($key,$msgdbg)  
  {	
	if(!$this->msgdebug)	{
		$this->msgdebug=array('0'.$key=>$msgdbg);		
		}
	else{	
		$this->msgdebug=array_merge($this->msgdebug,array(count($this->msgdebug).$key=>$msgdbg));		
		}
  }

  function showmsg($ntfmsg)
  {
	if(!$this->appmsg)	{
		$this->appmsg=array($ntfmsg);		
		}
	else{	
		$this->appmsg=array_merge($this->appmsg,array($ntfmsg));		
		}
  }

 
  function loadpage($vw,$data)
  {
	$data['user']=$this->loginuser;	
	$data['msg']=$this->appmsg;
	$this->load->view('scp/header', $data);		
	$this->load->view($vw, $data);	
	$this->load->view('scp/footer', $data);		
  }

  function loadpagewithjs($vw,$data,$js)
  {
  	$data['jspath']='<script src="'. base_url(APPPATH.  'assets/scripts/core/'.$js) .'" type="text/javascript"></script>';
	
	$this->load->view('scp/header', $data);		
	$this->load->view($vw, $data);			
	$this->load->view('scp/footer', $data);		
  }
  
  function appendhtmlwithjs($shtml,$data,$js,$usetemplate=true)
  {
	$this->append($shtml,$data,$js,$usetemplate);	
  }

  function appendhtml($shtml,$data,$usetemplate=true)
  {
		$this->append($shtml,$data,'',$usetemplate);
  }

  function append($shtml,$data,$js='',$usetemplate=true)
  {
	$templt='<div class="row">'
				.'<div class="col-md-12">'
				.'[RPLC]'
				.'</div>'
				.'</div>';
	
	if($js!='')
		$this->vwdata['jspath']='<script src="'. 
					 base_url(APPPATH.  'assets/scripts/app/'.$js) .'" type="text/javascript"></script>';
	
	if($this->msgdebug)
		$this->vwdata['msgdebug']=$this->msgdebug;

	if($this->appmsg)
		$this->vwdata['msg']=$this->appmsg;

	if($usetemplate)
		$shtml=str_replace('[RPLC]',$shtml,$templt);

	$this->vwdata['user']=$this->loginuser;	
	$this->vwdata['strhtml']=$shtml;		

	$this->load->view('scp/header',$this->vwdata);		
	$this->load->view('scp/appendhtml', $this->vwdata);			
	$this->load->view('scp/footer', $this->vwdata);	
  }
}

?>



